<%@include file="common/common.jsp"%>
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>

<meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
<meta name=format-detection content="telephone=no">

<meta name=robots content="noindex,nofollow,noarchive">

<meta name=author content="https://github.com/ErikDubbelboer/">

<title></title>

<link rel=stylesheet href="css/common.css?v1-1-1" media=all>
<link rel=stylesheet href="css/frame.css?v1-1-1" media=all>

<link rel="shortcut icon" href="images/favicon.png">

<script src="js/jquery.js?v1-1-1"></script>
<script src="js/frame.js?v1-1-1"></script>

</head>
<body>
<%if(jedis == null) { %>
<div style="text-align:center;color:red">Server Down</div>
<%}else{
	String key =request.getParameter("key"); 
	
	String keyType = jedis.type(key);
	String urlParam = "s=" + selectServer+"&key="+haiyaoyige(key)+"&type="+keyType;
	long ttl = jedis.ttl(key);
	String encoding = jedis.objectEncoding(key);
	
	// size
	long size = countKey(keyType, jedis, key);
%>
<h2><%=haiyaoyige(key)%>
	<a
		href="rename.jsp?<%=urlParam%>"><img
		src="images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a>
	<a
		href="delete.jsp?<%=urlParam%>"
		class="delkey"><img src="images/delete.png" width="16" height="16"
		title="Delete" alt="[X]"></a><%--  <a
		href="export.jsp?<%=urlParam%>"><img
		src="images/export.png" width="16" height="16" title="Export"
		alt="[E]"></a> --%>
		</h2>
	<%if(jedis.exists(key)) { %>
		<table>
		
		<tr><td><div>Type:</div></td><td><div><%=keyType %></div></td></tr>
		
		<tr><td><div><abbr title="Time To Live">TTL</abbr>:</div></td><td><div><%=ttl==-1?"does not expire" :ttl %> <a href="ttl.jsp?<%=urlParam%>"><img src="images/edit.png" width="16" height="16" title="Edit TTL" alt="[E]" class="imgbut"></a></div></td></tr>
		
		<%if(encoding != null){%>
		<tr><td><div>Encoding:</div></td><td><div><%=encoding %></div></td></tr>
		<%} %>
		<tr><td><div>Size:</div></td><td><div><%=size%> <%="string".equals(keyType) ? "characters" : "items"%></div></td></tr>
		</table>
		
		
		
		<!-- //String  -->
		<%if("string".equals(keyType)){ %>
		<table>
		<tr><td>
		<div><%=haiyaoyige(jedis.get(key)) %></div>
		</td><td>
		<div>
			<a href="edit.jsp?<%=urlParam %>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
		</div>
		</td><td>
		<div>
		  <a href="delete.jsp?<%=urlParam %>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
		</div>
		</td></tr>
		</table>
		
		<%}else if("hash".equals(keyType)){ %>
		
		<table>
		<tr><th><div>Key</div></th><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
			<%for(String hkey : jedis.hkeys(key)){ %>
	  		<tr class="alt"><td><div><%=haiyaoyige(hkey)%></div></td><td><div><%=haiyaoyige(jedis.hget(key, hkey)) %></div></td><td><div>
	    	<a href="edit.jsp?<%=urlParam %>&hkey=<%=haiyaoyige(hkey)%>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
	  		</div></td><td><div>
	    	<a href="delete.jsp?<%=urlParam %>&hkey=<%=haiyaoyige(hkey)%>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
  			</div></td></tr>
	  		<%} %>
	  		</table>
	  		
		<%}else if("list".equals(keyType)){ 
		%>
		
		<table>
		<tr><th><div>Index</div></th><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
		<%for(long index=0;index<size;index++){ %>
		<tr class="alt"><td><div><%=index %></div></td><td><div><%=haiyaoyige(jedis.lindex(key, index)) %></div></td><td><div>
    	<a href="edit.jsp?<%=urlParam %>&index=<%=index%>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
	 	 </div></td><td><div>
	    <a href="delete.jsp?<%=urlParam %>&index=<%=index%>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
	 	 </div></td></tr>
	 	 <%} %>
		</table>
		
		<%}else if("set".equals(keyType)){ %>
		<table>
			<tr><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
			<%for(String value : jedis.smembers(key)){ %>
			<tr class="alt"><td><div><a href="<%=jedis.exists(value)?"":"view.jsp?s="+selectServer+"&key="+haiyaoyige(value)%>"><%=haiyaoyige(value)%></a></div></td><td><div>
			<a href="edit.jsp?<%=urlParam %>&value=<%=haiyaoyige(value)%>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
			</div></td><td><div>
			  <a href="delete.jsp?<%=urlParam %>&value=<%=haiyaoyige(value)%>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
			</div></td></tr>
			<%} %>
		</table>
		
		<%}else if("zset".equals(keyType)){ %>
			<table>
			<tr><th><div>Score</div></th><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
			<%for(String member : jedis.zrange(key, 0, -1)){ %>
			<tr class="alt"><td><div><%=jedis.zscore(key, member) %></div></td><td><div><%=haiyaoyige(member) %></div></td><td><div>
			<a href="edit.jsp?<%=urlParam %>&score=<%=jedis.zscore(key, member) %>&amp;value=<%=haiyaoyige(member)%>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
			<a href="delete.jsp?<%=urlParam %>&amp;value=<%=haiyaoyige(member)%>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
			</div></td></tr>
			  <%} %>
		  	</table>
		<%} %>
	<%}else{ %>
		 This key does not exist.
	<%} %>
	
	<p>
		<a href="edit.jsp?<%=urlParam %>" class="add">Add another value</a>
	</p>
	<%} %>
</body>
</html>